package com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.bo.IWenTypeBO;
import com.tjsinfo.tjsoa.documentationflow.xingzhengfawen.vo.SubTypeInfo;

public class SelectTypeByItemAction extends Action{
	private IWenTypeBO wenTypeBO;
	
	public IWenTypeBO getWenTypeBO() {
		return wenTypeBO;
	}
	
	
	public void setWenTypeBO(IWenTypeBO wenTypeBO) {
		this.wenTypeBO = wenTypeBO;
	}


	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		Integer itemType = Integer.parseInt(request.getParameter("itemType"));
		List<SubTypeInfo> subTypeList = wenTypeBO.selectSubTypeByItem(itemType);
		JSONArray array = new JSONArray();
		for (SubTypeInfo subTypeInfo : subTypeList) {
			JSONObject	 object = new JSONObject();
			object.put("id", subTypeInfo.getId());
			object.put("typeName", subTypeInfo.getTypeName());
			array.put(object);
		}
		response.getWriter().print(array);
		return null;
	}
	
}

